﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>salary_standardThUpdate</title>
    <script src="~/lib/axios/dist/axios.js"></script>
    <script src="~/lib/vue/dist/vue.js"></script>
    <script src="~/lib/element-ui/lib/index.js"></script>
    <link href="~/lib/element-ui/lib/theme-chalk/index.css" rel="stylesheet" />
</head>
<body>
    <div id="app">
        <el-container>
            <el-header>
                <el-card class="box-card">
                    <el-col :span="4"> 薪酬标准变更 </el-col>
                </el-card>
            </el-header>
            <el-main>
                <el-card class="box-card">
                    <el-form ref="form"
                             :model="form"
                             :rules="formrule"
                             :inline="true"
                             label-width="80px">
                        <el-row>
                            <el-form-item class="_klpo">
                                <template>
                                    <el-button type="primary" @@click="submitForm('form')">重新提交</el-button>
                                </template>
                                <el-button @@click="eas()">返回</el-button>
                            </el-form-item>
                        </el-row>
                        <el-form-item label="薪酬标准编号" prop="standard_id" label-width="96px">
                            <el-input v-model="form.standard_id" style="width: 148px" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="薪酬标准名称" prop="standard_name" label-width="107px">
                            <el-input v-model="form.standard_name" style="width: 210px"></el-input>
                        </el-form-item>
                        <el-form-item label="薪酬总额" prop="salary_sum">
                            <el-input v-model="form.salary_sum" style="width: 162px" :disabled="true"></el-input>
                        </el-form-item>
                        <el-form-item label="制定人" prop="designer" label-width="65px">
                            <template>
                                <el-select v-model="form.designer" placeholder="请选择制定人" style="width: 200px " :disabled="true">
                                    <el-option v-for="item in listm"
                                               :key="item.u_id"
                                               :label="item.u_true_name"
                                               :value="item.u_true_name">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item label="变更人" prop="changer" label-width="65px">
                            <template>
                                <el-select v-model="form.changer" placeholder="请选择变更人" style="width: 190px ">
                                    <el-option v-for="item in listm"
                                               :key="item.u_id"
                                               :label="item.u_true_name"
                                               :value="item.u_true_name">
                                    </el-option>
                                </el-select>
                            </template>
                        </el-form-item>
                        <el-form-item prop="change_time" label="变更时间" label-width="96px">
                            <el-date-picker style="width: 221px " :disabled="true" type="datetime" placeholder="选择变更时间" v-model="form.change_time"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="备注" prop="remark" label-width="40px">
                            <el-input type="textarea" v-model="form.remark" style="width: 1072px " autosize></el-input>
                        </el-form-item>
                        <el-table :data="list" border stripe style="height: 244px; overflow: auto;">
                            <el-table-column prop="item_id"
                                             label="序号"
                                             align="center">
                            </el-table-column>
                            <el-table-column prop="item_name"
                                             label="薪酬项目名称"
                                             align="center">
                            </el-table-column>
                            <el-table-column label="金额" align="center">
                                <template slot-scope="scope">
                                    <el-input v-model.number="scope.row.salary"  @@input="js(scope.row)" oninput="value=value.replace(/[^\d.]/g,'')"></el-input>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-form>
                </el-card>
            </el-main>
        </el-container>

    </div>
    <script type="text/javascript">
        var vm = new Vue({
            el: "#app",
            data: {
                list: [],
                je: [],//薪酬名称和金额
                listm:[],//用户
                form: {
                    sdt_id:'',
                    ssd_id:'',
                    standard_id: '',
                    standard_name: '',
                    designer: '',
                    changer: '',
                    change_time: '',
                    salary_sum: '',
                    remark: '',
                    salary: '',
                },
                formrule: {
                    standard_name: [
                        { required: true, message: '请输入标准名', trigger: 'blur' }
                    ],
                    changer: [
                        { required: true, message: '请选择变更人', trigger: 'change' }
                    ],
                    salary_sum: [
                        { required: true, message: '请输入金额', trigger: 'blur' }
                    ],
                }
            },
            methods: {
                js(row) {
                    this.je = [];
                    row.salary = row.salary == "" ? 0 : parseInt(row.salary);
                    this.form.salary_sum = 0;//薪酬总额
                    for (var index in this.list) {
                        if (this.list[index].salary != null) {
                            this.form.salary_sum += parseInt(this.list[index].salary);//金额相加
                            var ohj = {};
                            ohj.sdt_id = this.list[index].sdt_id;
                            ohj.pbc_id = this.list[index].item_id;//id
                            ohj.attribute_name = this.list[index].item_name;//薪酬名字
                            ohj.salary = this.list[index].salary;//薪酬金额
                            this.je.push(ohj);
                        }
                    }
                },
                submitForm(formName) {
                    //表单验证
                    this.$refs[formName].validate((valid) => {
                        if (valid) {
                                this.$confirm('此操作将修改薪酬信息, 是否修改?', '提示', {
                                    confirmButtonText: '确定',
                                    cancelButtonText: '取消',
                                    type: 'warning'
                                }).then(() => {
                                    //薪酬基本修改
                                    axios.get('/salary_standardTh/Upte', {
                                        params: {
                                            standard_name: this.form.standard_name,
                                            changer: this.form.changer,
                                            change_time: this.form.change_time,
                                            salary_sum: this.form.salary_sum,
                                            remark: this.form.remark,
                                            ssd_id: @ViewBag.ssd_id,
                                        }
                                    })
                                        .then(res => {
                                            console.info(res);
                                            if (res.data == 1 && this.je.length>0) {
                                                for (let index in this.je) {
                                                      //薪酬详细修改
                                                    axios.get('/salary_standardTh/UpteTo', {
                                                        params: {
                                                            sdt_id: this.je[index].sdt_id,
                                                            standard_name: this.form.standard_name,
                                                            salary: this.je[index].salary,
                                                        }
                                                    })
                                                        .then(res => {
                                                            console.info(res);
                                                        })
                                                        .catch(err => {
                                                            console.info(err);
                                                        })
                                                }
                                            }
                                            this.$message({
                                                type: 'success',
                                                message: '修改成功!'
                                            });
                                            this.eas();
                                        })
                                        .catch(err => {
                                            console.info(err);
                                        })
                                }).catch(() => {
                                    this.$message({
                                        type: 'info',
                                        message: '已取消修改'
                                    });
                                });
                        } else {
                            this.$message({
                                type: 'error',
                                message: '请填写完整信息!'
                            });
                            return false;
                        }
                    });
                },
                eas() {
                    location.href = "/salary_standardTh/salary_standardTh";
                },
                fill() {
                    //用户查询
                    axios.get('/users/que', {
                    })
                        .then(res => {
                            console.info(res);
                            this.listm = res.data;
                        })
                        .catch(err => {
                            console.info(err);
                        });
                     //薪酬查询
                     axios.get('/salary_standardTo/Chui/'+@ViewBag.ssd_id)
                        .then(res => {
                            console.info(res);
                            this.form.standard_id = res.data.standard_id;
                            this.form.standard_name = res.data.standard_name;
                            this.form.designer = res.data.designer;
                            this.form.salary_sum = res.data.salary_sum;
                            this.form.remark = res.data.remark;
                            this.sz = res.data.salary_sum;
                             //薪酬详细数据表查询
                            axios.get('/salary_standardTo/ChuiTo', {
                                params: {
                                    id: res.data.standard_id,
                                }
                            })
                                .then(res => {
                                    console.info(res);
                                    this.list = res.data;
                                })
                                .catch(err => {
                                    console.info(err);
                                });
                        })
                        .catch(err => {
                            console.info(err);
                        });
                },
                get() {
                    //当前时间
                    this.form.change_time = new Date();
                },
            },
            mounted() {
                //时间计时器
                setInterval(this.get, 1000);
            },
            //可以对vue的数据和方法进行操作,不能对DOM进行操作
            created: function () {
                this.fill();
            }
        });
    </script>
    <style>
        .el-col-4 {
            width: 20%;
            font-size: 15px;
            font-weight: 900;
            line-height: 0px;
        }
        .el-form-item {
            margin-bottom: 17px;
        }
        element.style {
            height: 100%;
            width: 1239px;
        }
        .el-card__body {
            padding: 35px;
        }
        .el-button.is-circle {
            border-radius: 50%;
            padding: 12px;
            position: relative;
            top: -10px;
            right: -570px;
        }

        ._klpo {
            float: right;
        }
    </style>
</body>
</html>
